package cn.mumzone.pos.presenter;

import java.util.List;

import cn.mumzone.basic.mvp.AbsPresenter;
import cn.mumzone.basic.net.http.callback.ApiCallBack;
import cn.mumzone.basic.net.response.BaseResponse;
import cn.mumzone.pos.model.OffWorkSumAmountEntity;
import cn.mumzone.pos.model.OffWorkSumAmountResult;
import cn.mumzone.pos.model.OffWorkTicketEntity;
import cn.mumzone.pos.model.source.UserRepository;
import cn.mumzone.pos.presenter.contract.OffWorkContract;

/**
 * Created by qiuzhenhuan on 2019/7/6.
 */

public class OffWorkPresenter extends AbsPresenter<OffWorkContract.View,UserRepository> implements OffWorkContract.Presenter {


    @Override
    public void loadHandOverInfo() {
        ApiCallBack<OffWorkSumAmountResult> callBack = new ApiCallBack<OffWorkSumAmountResult>() {
            @Override
            public void onSuccess(OffWorkSumAmountResult result) {
                mView.showHandOverInfo(result);
            }

            @Override
            public void onError(BaseResponse response) {
                mView.showError(response.getMsg());
            }
        };
        mRepo.offWorkSumAmount(callBack);
        addSubscrebe(callBack);

    }

    @Override
    public void doShiftExchange(String cashAmount) {
        ApiCallBack<String> callBack = new ApiCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                loadShiftDetail(result);
            }

            @Override
            public void onError(BaseResponse response) {
                mView.showError(response.getMsg());
            }
        };
        mRepo.shiftExchange(cashAmount, callBack);
        addSubscrebe(callBack);
    }

    @Override
    public void loadShiftDetail(String id) {
        ApiCallBack<OffWorkTicketEntity> callBack = new ApiCallBack<OffWorkTicketEntity>() {
            @Override
            public void onSuccess(OffWorkTicketEntity entity) {
                mView.showShiftDetail(entity);
                mView.showShiftExchangeSuccess();
                mRepo.clearUserInfo();
            }

            @Override
            public void onError(BaseResponse response) {
                mView.showShiftExchangeSuccess();
                mRepo.clearUserInfo();
            }
        };
        mRepo.getShiftRecordDetail(id,callBack);
        addSubscrebe(callBack);

    }
}
